<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Input;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;


    public function imageUpload($rootPath='')
    {
        $file = Input::file("Filedata");
        $rootPath = Input::get("rootPath");
        if($file->isValid()){
            $path = $file->getRealPath();

            $extention = $file->getClientOriginalExtension();

            $newName = time().mt_rand(100,999).'.'.$extention;

            $path = base_path().'/public/uploads/'.$rootPath.'/';

            if(!is_dir($path)) mkdir($path,0777,true);

            $upload = $file->move($path,$newName);

            return 'public/uploads/'.$rootPath.'/'.$newName;
        }
    }
}
